#include<stdio.h>
int main()
{
	int arr[10], * p1, * p2, t;
	int *b1, *b2;
	int i;
	for (i = 0; i < 10; i++)
		scanf_s("%d", &arr[i]);
	b1 = arr;
	p1 = arr + 1;
	for (i = 1; i < 10; i++)
	{
		if (*p1 > *b1)
			b1 = p1;
		p1++;
	}
	t = *b1;
	*b1 = arr[9];
	arr[9] = t;
	b2 = arr;
	p2 = arr + 1;
	for (i = 1; i < 10; i++)
	{
		if (*p2 < *b2)
			b2 = p2;
		p2++;
	}
	t = *b2;
	*b2 = arr[0];
	arr[0] = t;
	for(i = 0;i < 10;i++)
	printf("%d\n", arr[i]);
	return 0;
	}